import {
  manageList,
  getInfo,
  typeAdd,
  typeEdit
} from '@/api/manage'
import utils from '@/utils/common'
var timeStamp = Number(new Date())
const manage = {
  state: {},

  mutations: {},

  actions: {
    // 分类列表
    ManageList ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        keyword: data.keyword,
        enabled: data.enabled,
        parentId: data.parentId,
        page: data.page,
        pageSize: data.pageSize
      }
      return new Promise((resolve, reject) => {
        manageList(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 分类获取
    GetTypeInfo ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id
      }
      return new Promise((resolve, reject) => {
        getInfo(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 分类编辑
    TypeEdit ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id,
        name: data.name,
        iconUrl: data.iconUrl,
        enabled: data.enabled,
        remark: data.remark,
        seqNum: data.seqNum
      }
      return new Promise((resolve, reject) => {
        typeEdit(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 分类添加
    TypeAdd ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        name: data.name,
        iconUrl: data.iconUrl,
        parentId: data.parentId,
        enabled: data.enabled,
        remark: data.remark,
        seqNum: data.seqNum
      }
      return new Promise((resolve, reject) => {
        typeAdd(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }

  }
}

export default manage
